package com.gitee.slowcreator.http.enhance.factory;

import com.gitee.slowcreator.http.enhance.HttpRequestHandle;

import java.lang.reflect.Proxy;

/**
 * @author zxw
 * @date 2023/1/7 下午9:40
 */
public class HttpProxyFactory<T> {

    private final Class<T> httpInterface;

    public HttpProxyFactory(Class<T> httpInterface) {

        this.httpInterface = httpInterface;
    }

    @SuppressWarnings("unchecked")
    protected T newInstance(HttpRequestHandle<T> httpProxy) {

        return (T) Proxy.newProxyInstance(httpInterface.getClassLoader(), new Class[]{httpInterface}, httpProxy);
    }
}
